<% if Cms::CategoryType.count > 0 %>

  <% @block.category_type ||= (Cms::Category.includes(:category_type).last && Cms::Category.last.category_type) %>
  <%= f.association :category_type,
                    collection: Cms::CategoryType.order("name"),
                    :prompt => "Select a Type of Category",
                    :label => "Type" %>

  <% categories = @block.category_type ? @block.category_type.category_list : [] %>
  <% unless categories.empty? %>
    <%= f.association :parent, collection: categories, :include_blank => true %>
  <% end %>

  <%= f.input :name %>

<% else %>
  <% use_page_title "Please Create A Category Type" %>
  <%= content_for :html_head do %>
    <script type="text/javascript">
      $(function(){
        $('.form-actions, .top-buttons').remove();
      });
    </script>
  <% end %>
  <p>Before you can create a category, you must create at least one category type for that category. For example, if you plan to categorize your news releases, you might create a "News Release" category type.</p>
    <%= link_to "Add a New Category Type", new_category_type_path, class: 'btn btn-primary btn-small' %>
<% end %>
